package com.kpmg.datalake.common.utils;

import com.kpmg.datalake.common.enums.ResultCodeEnum;
import com.kpmg.datalake.common.exception.BusinessException;
import com.kpmg.datalake.common.vo.ServerResponse;

import java.io.Serializable;

/**
 * @author Alex.zhao [alex.zhao@kpmg.com]
 * @since Created on azhao6 on 2018-07-20 00:14:59
 */
public class ExceptionUtil {

    private ExceptionUtil() {

    }

    /**
     * 通用异常信息处理工具
     *
     * @param e   异常信息
     * @param <T> 类型
     * @return 返回实体
     */
    public static <T extends Serializable> ServerResponse<T> getExceptionMsg(Exception e) {
        ResultCodeEnum resultCodeEnum = ResultCodeEnum.CODE9999;
        if (e instanceof BusinessException) {
            resultCodeEnum = ((BusinessException) e).getResultCodeEnum();
        }
        return ServerResponse.createByErrorCodeMessage(resultCodeEnum, e.getLocalizedMessage());

    }
}
